package com.easy.auth.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easy.auth.domain.Reportlog;
import com.easy.auth.domain.Waring;
import com.easy.auth.service.WaringService;
import com.easy.common.jdbc.PageInfo;
import com.easy.common.tool.email.MailSenderInfo;
import com.easy.common.tool.email.SimpleMailSender;
import com.easy.common.web.FilterUtil;
import com.easy.common.web.PagedList;
import com.easy.common.web.message.DeleteMessage;
import com.easy.common.web.message.Message;
import com.easy.common.web.message.SaveOrEditMessage;
@Controller
@RequestMapping("WaringController")
public class WaringController {
	@Autowired
	private WaringService waringService;

	@RequestMapping("goToWaringManager")
	public String goToActionManager(String secondMenuId,HttpServletRequest request) {
		request.getSession().setAttribute("secondMenuId", secondMenuId);
		return "auth/waring";
	}

	/**
	 * 查询全部节点数据
	 * 
	 * @return
	 */
	@RequestMapping("getWaringList")
	@ResponseBody
	public PagedList<Waring> getWaringList(PageInfo pageInfo) {
		Waring waring = (Waring) FilterUtil.getVO(Waring.class,
				pageInfo.getFilterRules());
		return waringService.getAllWarings(waring, pageInfo);
	}

	/**
	 * 根据oid查询该节点其他数据
	 * 
	 * @return
	 */
	@RequestMapping("findWaringById")
	@ResponseBody
	public Waring findWaringById(Waring waring) {
		return waringService.findWaringById(waring);
	}
	/**
	 * 新增或编辑用户
	 * 
	 * @param Waringinfo
	 * @return
	 */
	@RequestMapping("saveOrEditWaring")
	@ResponseBody
	public Message saveOrEditWaring(Waring waringinfo) {
		return new SaveOrEditMessage(
				waringService.saveOrEditWaring(waringinfo));
	}
	
	@RequestMapping("saveChangeTime")
	@ResponseBody
	public Message saveChangeTime(Waring waringinfo) {
		String changeTime=waringinfo.getOname();
		//System.out.println("```````````````````"+waringinfo.getStart_time());
		waringinfo.setChange_log(changeTime+","+waringinfo.getChange_log());
		waringinfo.setChange_time(changeTime);
		waringinfo.setOname("");
		return new SaveOrEditMessage(
				waringService.saveOrEditWaring(waringinfo));
	}
	
	/**
	 * 保存资源信息
	 * 
	 * @param param
	 * @param request
	 * @return
	 */
	@RequestMapping("saveWaring")
	@ResponseBody
	public Message saveTreegrid(Waring waring) {
		int count = waringService.saveWaring(waring);
		return new SaveOrEditMessage(count);
	}

	/**
	 * 删除资源信息
	 * 
	 * @param param
	 * @param request
	 * @return
	 */
	@RequestMapping("removeWarings")
	@ResponseBody
	public Message removeTreegrid(String oids) {
		String[] ids = oids.split("-");
		return new DeleteMessage(waringService.removeWarings(ids));
	}
	
	
	
}
